Views are elements which allow User to interact with your Application - this is known as User Interface (UI).
Views can be added and configured through: Code, Automatic Preview or Library.
We can categorize Views based on their purpose into
● Visible Views present some visual information to the User (Label, Text Field, Button, Image View)
● Container Views are used to contain other Views (Horizontal/Vertical Stack, Navigation View)
● Helper Views are also invisible but can't contain other Views (Spacer, Divider)
(Container and Helper Views allow us to more easily organize Visible Views and navigate through them)
Your application will contain one or more Screens which are shown as iPhones in your Automatic Preview.
Each Screen actually represents a single root View which is container for all other Views.
This root View can have many Sub Views each of which can have their own Sub Views which results in a View Hierarchy.
To switch between Screens (and transfer data) use NavigationView in combination with NavigatinLink.
When you create new Project below code s automatically generated which creates 2 Views
● Content View is Root View and takes up the whole Screen (it has iPhone frame around it)
● Text View is Sub View inside the Content View positioned at its center taking only as much space as it needs
ContentView.swift
struct ContentView : View {
var body : some View {
Text("Some Text").border(Color.red, width: 2)
}
}
Content View with Text View inside it at the center